import { useReactive } from "ahooks";
import { useEffect } from "react";
import { useModel } from "umi";

const useRemoteApplicationAuthorization = () => {
    const { remoteData } = useModel("global");

    const state = useReactive({
        loading: false,
        remoteApplicationAuthorization: {},
    });

    // 从务链应用运营中心获取应用授权信息, 通过应用UUID, 组织UUID
    const loadRemoteApplicationAuthorization = async (aiUuid) => {
        state.loading = true;
        let res = await remoteData({
            object: "bnt-application-operation-center-service",
            serviceName: "/person/application/authorization/information",
            showError: false,
            params: {
                aiUuid,
            },
        });
        // res && (state.remoteApplicationAuthorization = res);
        state.loading = false;
        return res || {};
    };

    // useEffect(() => {
    //     loadRemoteApplicationAuthorization();
    // }, []);

    return { ...state, loadRemoteApplicationAuthorization };
};

export default useRemoteApplicationAuthorization;
